﻿#include "roleservice.h"
#include <databasecenter.h>
#include <QDebug>

RoleService::RoleService(QObject *parent) : QObject(parent)
{
    db = DatabaseCenter::getInstance().getConnection();
}

RoleService::~RoleService()
{
    DatabaseCenter::getInstance().releaseConnection(db);
}

bool RoleService::getPermissionsByCodes(QList<QString> &permissions,const QList<QString> codes)
{
    RoleDao objectDao(db);
    QList<Role> list;
    if(!objectDao.getList(list)){
        return false;
    }
    for(Role &item:list){
        if(codes.contains(item.getCode())){
            permissions.append(item.getPermissions());
        }
    }
    return true;
}

bool RoleService::getPageList(uint64_t &total, QList<Role> &list, const uint64_t &page, const uint64_t &pageSize)
{
    RoleDao objectDao(db);
    return (objectDao.getTotalByParam(total) && objectDao.getPageListByParam(list,page,pageSize));
}


bool RoleService::getList(QList<Role> &list)
{
    RoleDao objectDao(db);
    return (objectDao.getList(list));
}

bool RoleService::getOne(Role &object)
{
    RoleDao objectDao(db);
    return (objectDao.getOne(object));
}

bool RoleService::saveOne(Role &object,QBaseEntity::PropertiesType propertiesType,QStringList properties)
{
    RoleDao objectDao(db);
    return (objectDao.saveOne(object,propertiesType,properties));
}

bool RoleService::deleteOne(Role &object)
{
    RoleDao objectDao(db);
    return (objectDao.deleteOne(object));
}

